﻿
namespace SistemaLogistica.DataAccess
{
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using SistemaLogistica.Business.Entities;

    public class DetalleNotaIngresoData:BaseDataAccess
    {
        private DetalleNotaIngresoData() { }

        private static readonly DetalleNotaIngresoData instancia = new DetalleNotaIngresoData();

        public static DetalleNotaIngresoData Instancia
        {
            get { return instancia; }
        }

        public List<DetalleNotaIngreso> ListarPorNotaIngreso(int notaIngresoID)
        {
            List<DetalleNotaIngreso> detalleNotaIngreso = new List<DetalleNotaIngreso>();
            DbCommand command = db.GetStoredProcCommand("GetDetalleNotaIngresoByNotaIngresoID");
            db.AddInParameter(command, "idNotaIngreso", DbType.Int32, notaIngresoID);

            using (IDataReader dr = db.ExecuteReader(command))
            {
                while (dr.Read())
                {
                    detalleNotaIngreso.Add(new DetalleNotaIngreso
                    {
                        Bien = BienData.Instancia.ObtenerPorID(dr.GetInt32(dr.GetOrdinal("IdBien"))),
                        Cantidad = dr.GetDecimal(dr.GetOrdinal("Cantidad")),
                        Precio = dr.GetDecimal(dr.GetOrdinal("Precio")),
                        IdNotaIngreso = dr.GetInt32(dr.GetOrdinal("IdNotaIngreso"))
                    });
                }
            }
            return detalleNotaIngreso;
        }
    }
}
